package com.ygqh.baby.excel.exception;

import com.foxinmy.weixin4j.util.StringUtil;

/**
 * 〈〉
 *
 * @author guohao
 * @date 2019/4/19 13:07
 * @since 1.0.0
 */
public class ExcelException extends RuntimeException {

    private String errorCode;
    private String errorMsg;

    public ExcelException(String errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public ExcelException(String errorMsg) {
        this.errorCode = "-1";
        this.errorMsg = errorMsg;
    }

    public ExcelException(Throwable e) {
        super(e);
    }

    public ExcelException(String message, Throwable cause) {
        super(message, cause);
    }

    public String getErrorCode() {
        return errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    @Override
    public String getMessage() {
        StringBuilder buf = new StringBuilder();
        if (StringUtil.isNotBlank(errorCode)) {
            buf.append(errorCode);
        }
        if (StringUtil.isNotBlank(errorMsg)) {
            buf.append(" ").append(errorMsg);
        }
        if (buf.length() == 0) {
            return super.getMessage();
        }
        return buf.toString();
    }
}
